package com.example.client.zkClient;

import com.example.client.ZKConstans;
import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;

import java.util.List;

/**
 * @author Creared by wangyang on 2019-01-28 17:35
 * email:techyang.wangy.@ymm56.com
 */
public class GetChildrenSample {

    public static void main(String[] args) throws InterruptedException {
        ZkClient zkClient = new ZkClient(ZKConstans.CONNECTOR_STRING, 5000);
        String path = "/zk-book";
        zkClient.subscribeChildChanges(path, new IZkChildListener() {
            @Override
            public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
                System.out.println(parentPath + " 's child changed, currentChilds:" + currentChilds);
            }
        });
        zkClient.createPersistent(path);
        Thread.sleep(1000);
        System.out.println(zkClient.getChildren(path));
        Thread.sleep(1000);
        zkClient.createPersistent(path + "/c1");
        Thread.sleep(1000);
        zkClient.delete(path + "/c1");
        Thread.sleep(1000);
        zkClient.delete(path);
        Thread.sleep(Integer.MAX_VALUE);
    }
}
